<tr><th colspan="6" id="task_action"><%= task.new_record? ? "New Task" : "Update #{task.title}" %></th></tr>
<tr>
  <td colspan="6" style="padding:0">
    <% remote_form_for :task, task, :url => polymorphic_path([:admin, task]), :html => {:class => "remote_form", :id => "task_form", :method => task.new_record? ? :post : :put } do |task_form| %>
      <table id="task_form_table">
        <tr>
          <th>Title</th>
          <th>Sub-Contractor</th>
          <th>Started</th>
          <th>Status</th>
          <th>Completed</th>
          <th></th>
        </tr>
        <tr>  
          <td class="title"><%= task_form.text_field :title %></td>
          <td class="sub_contractor_id"><%= task_form.select(:sub_contractor_id, SubContractor.all.collect{|p| [p.name, p.id]}, { :include_blank => true }) %></td>
          <td class="started_on"><%= task_form.text_field :started_on, :id => "task_started_on_date_picker", :class => "date_picker", :value => task.started_on.blank? ? "" : task.started_on.to_s(:numeric) %></td>
          <td class="status_code"><%= task_form.select(:status_code, STATUS_CODES.collect{|p| [ p[:text], p[:db_code] ] }, { :include_blank => false }) %></td>
          <td class="completed_on">
            <span id="task_completed_on_box" style="display:none;"><%= task_form.text_field :completed_on, :id => "task_completed_on_date_picker", :class => "date_picker", :value => task.completed_on.blank? ? "" : task.completed_on.to_s(:numeric) %></span>
          </td>
          <td class="table_buttons">
            <%= task_form.hidden_field :milestone_id, :value => milestone.id %>
            <%= task_form.submit (task.new_record? ? "Add" : "Save") %>
          </td>
        </tr>
      </table>
    <% end %>    
  </td>
</tr>
  
<script type="text/javascript">
  $j( "#task_started_on_date_picker" ).datepicker({ nextText: '&rarr;', prevText: '&larr;' });
  $j( "#task_completed_on_date_picker" ).datepicker({ nextText: '&rarr;', prevText: '&larr;' });
  
  $j("#task_status_code").bind("change", function() {
    if(this.value == "3"){
      $j("#task_completed_on_box").fadeIn();
    }else{
      $j("#task_completed_on").val("");
      $j("#task_completed_on_box").fadeOut();
    }
  });
  
</script>